/**
 * 
 */
package com.nari.heatshare.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.nari.baseinfo.dao.IBuildingDao;
import com.nari.baseinfo.dao.ICityDao;
import com.nari.baseinfo.dao.ICommunityDao;
import com.nari.baseinfo.dao.IHeatRoomDao;
import com.nari.baseinfo.model.ICommunity;
import com.nari.coreframe.service.GenericServiceImpl;
import com.nari.heatshare.dao.IShareAreaResultDao;
import com.nari.heatshare.dao.IUserShareResultDao;
import com.nari.heatshare.dao.springjdbc.IUserShareResultJdbcDao;
import com.nari.heatshare.model.IUserShareResult;
import com.nari.heatshare.utils.excelexport.heatcharge.vo.AreaResultBillListVo;
import com.nari.platform.model.PageCond;
import com.nari.platform.model.ResultWithPageCond;

/**
 * 
 * @author Xiaopeng
 * @date 2013-8-19
 */
public class UserShareResultServiceImpl extends GenericServiceImpl<IUserShareResult, String>
		implements IUserShareResultService {
	private IShareAreaResultDao iShareAreaResultDao;
	private IUserShareResultJdbcDao iUserShareResultJdbcDao;
	private IHeatRoomDao iHeatRoomDao;
	private IBuildingDao iBuildingDao;
	private ICommunityDao iCommunityDao;
	private ICityDao iCityDao;

	/**
	 * 分页查询用户分摊结果
	 * @param projectUID 所属项目(可选)
	 * @param communityUID 所属小区(可选)
	 * @param buildingUID 所属楼栋(可选)
	 * @param heatRoomUID 所属热用户(可选)
	 * @param pageCond
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-10-6
	 */
	public ResultWithPageCond<IUserShareResult> queryUserShareResultPage(String projectUID, 
			String communityUID, String buildingUID, String heatRoomUID, 
			PageCond pageCond) throws Exception {
		IUserShareResultDao iUserShareResultDao = (IUserShareResultDao) this.getiGenericDao();
		return iUserShareResultDao.queryUserShareResultPage(projectUID, communityUID, buildingUID, heatRoomUID, pageCond);
	}
	
	/**
	 * 通过用户分摊列表查询与之关联的城市映射表
	 * @param userShareResultList 用户分摊列表，若列表为空，则返回空的映射表
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-10-6
	 */
	public Map<String, String> queryReferCityMap(List<IUserShareResult> userShareResultList) throws Exception {
		List<String> cityIDList = null;
		if(userShareResultList!=null && userShareResultList.size()>0) {
			cityIDList = new ArrayList<String>();
			for(IUserShareResult userShareResult: userShareResultList) {
				ICommunity community = iCommunityDao.queryEntityById(userShareResult.getCommunityID());
				cityIDList.add(community.getProvinceCityID());
				cityIDList.add(community.getCapitalCityID());
				cityIDList.add(community.getDistrictCityID());
			}
		}
		return iCityDao.queryIdNameMapByIDList(cityIDList);
	}
	
	/**
	 * 通过用户分摊列表查询与之关联的小区映射表
	 * @param userShareResultList 用户分摊列表，若列表为空，则返回空的映射表
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-10-6
	 */
	public Map<String, String> queryReferCommunityMap(List<IUserShareResult> userShareResultList) throws Exception {
		List<String> communityIDList = null;
		if(userShareResultList!=null && userShareResultList.size()>0) {
			communityIDList = new ArrayList<String>();
			for(IUserShareResult userShareResult: userShareResultList) {
				communityIDList.add(userShareResult.getCommunityID());
			}
		}
		return iCommunityDao.queryIdNameMapByIDList(communityIDList);
	}
	
	/**
	 * 通过用户分摊列表查询与之关联的楼栋映射表
	 * @param userShareResultList 用户分摊列表，若列表为空，则返回空的映射表
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-10-6
	 */
	public Map<String, String> queryReferBuildingMap(List<IUserShareResult> userShareResultList) throws Exception {
		List<String> buildingIDList = null;
		if(userShareResultList!=null && userShareResultList.size()>0) {
			buildingIDList = new ArrayList<String>();
			for(IUserShareResult userShareResult: userShareResultList) {
				buildingIDList.add(userShareResult.getBuildingID());
			}
		}
		return iBuildingDao.queryIdNameMapByIDList(buildingIDList);
	}
	
	/**
	 * 通过用户分摊列表查询与之关联的热用户映射表
	 * @param userShareResultList 用户分摊列表，若列表为空，则返回空的映射表
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-10-6
	 */
	public Map<String, String> queryReferRoomMap(List<IUserShareResult> userShareResultList) throws Exception {
		List<String> roomIDList = null;
		if(userShareResultList!=null && userShareResultList.size()>0) {
			roomIDList = new ArrayList<String>();
			for(IUserShareResult userShareResult: userShareResultList) {
				roomIDList.add(userShareResult.getRoomId());
			}
		}
		return iHeatRoomDao.queryIdNameMapByIDList(roomIDList);
	}
	
	/**
	 * 通过用户分摊列表查询与之关联的分摊域分摊映射表
	 * @param userShareResultList 用户分摊列表，若列表为空，则返回空的映射表
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-10-6
	 */
	public Map<String, String> queryReferShareResultMap(List<IUserShareResult> userShareResultList) throws Exception {
		List<String> shareResultIDList = null;
		if(userShareResultList!=null && userShareResultList.size()>0) {
			shareResultIDList = new ArrayList<String>();
			for(IUserShareResult userShareResult: userShareResultList) {
				shareResultIDList.add(userShareResult.getAreaResultID());
			}
		}
		return iShareAreaResultDao.queryShareResultMapByIDList(shareResultIDList);
	}
	
	/**
	 * 通过分摊域分摊ID分页查询所属的用户分摊列表
	 * @param areaResultUID 分摊域分摊ID(必填)
	 * @param roomOwner 户主姓名(可选)
	 * @param houseNo 门牌号(可选)
	 * @param pageCond
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-10-16
	 */
	public ResultWithPageCond<IUserShareResult> queryUserPageByAreaResultUID(String areaResultUID, 
			String roomOwner, String houseNo, PageCond pageCond) throws Exception {
		IUserShareResultDao iUserShareResultDao = (IUserShareResultDao) this.getiGenericDao();
		return iUserShareResultDao.queryUserPageByAreaResultUID(areaResultUID, roomOwner, houseNo, pageCond);
	}
	
	/**
	 * 查询分摊域分摊账单列表信息（分摊域下的用户账单）摘要
	 * @param areaResultUID
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2015-4-2
	 */
	public List<AreaResultBillListVo> queryAreaResultExportList(String areaResultUID) throws Exception {
		return iUserShareResultJdbcDao.queryAreaResultExportList(areaResultUID);
	}

	/**
	 * @return the iShareAreaResultDao
	 */
	public IShareAreaResultDao getiShareAreaResultDao() {
		return iShareAreaResultDao;
	}

	/**
	 * @param iShareAreaResultDao the iShareAreaResultDao to set
	 */
	public void setiShareAreaResultDao(IShareAreaResultDao iShareAreaResultDao) {
		this.iShareAreaResultDao = iShareAreaResultDao;
	}

	/**
	 * @return the iUserShareResultJdbcDao
	 */
	public IUserShareResultJdbcDao getiUserShareResultJdbcDao() {
		return iUserShareResultJdbcDao;
	}

	/**
	 * @param iUserShareResultJdbcDao the iUserShareResultJdbcDao to set
	 */
	public void setiUserShareResultJdbcDao(
			IUserShareResultJdbcDao iUserShareResultJdbcDao) {
		this.iUserShareResultJdbcDao = iUserShareResultJdbcDao;
	}

	/**
	 * @return the iHeatRoomDao
	 */
	public IHeatRoomDao getiHeatRoomDao() {
		return iHeatRoomDao;
	}

	/**
	 * @param iHeatRoomDao the iHeatRoomDao to set
	 */
	public void setiHeatRoomDao(IHeatRoomDao iHeatRoomDao) {
		this.iHeatRoomDao = iHeatRoomDao;
	}

	/**
	 * @return the iBuildingDao
	 */
	public IBuildingDao getiBuildingDao() {
		return iBuildingDao;
	}

	/**
	 * @param iBuildingDao the iBuildingDao to set
	 */
	public void setiBuildingDao(IBuildingDao iBuildingDao) {
		this.iBuildingDao = iBuildingDao;
	}

	/**
	 * @return the iCommunityDao
	 */
	public ICommunityDao getiCommunityDao() {
		return iCommunityDao;
	}

	/**
	 * @param iCommunityDao the iCommunityDao to set
	 */
	public void setiCommunityDao(ICommunityDao iCommunityDao) {
		this.iCommunityDao = iCommunityDao;
	}

	/**
	 * @return the iCityDao
	 */
	public ICityDao getiCityDao() {
		return iCityDao;
	}

	/**
	 * @param iCityDao the iCityDao to set
	 */
	public void setiCityDao(ICityDao iCityDao) {
		this.iCityDao = iCityDao;
	}
	
}
